package com.ymatou.iapi.thirdpartysync.testcase;

import java.util.List;

import org.junit.After;

import com.google.gson.JsonArray;
import com.ymatou.iapi.thirdpartysync.parameter.*;
import com.ymatou.iapi.thirdpartysync.service.*;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.ThirdpartysyncCallService;
import com.ymttest.database.model.thirdpartysync.promoter;
import com.ymttest.database.sqlwapper.thirdpartysync.DefThirdpartysyncWapper;
/**
*查询推广达人列表Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetPromoters{
	private static GetPromotersBean getpromotersBean;
	private static GetPromotersCall getpromotersCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询推广达人列表Test");
	}

	@Before
	public void caseUp() {
		getpromotersBean=new GetPromotersBean();
		getpromotersCall=new GetPromotersCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getpromotersCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPromoters_001() {
		Logger.start(true,"查询所有推广达人与数据库校验，成功");
		try {
			getpromotersCall.setData(getpromotersBean);
			getpromotersCall.callService();			
			Logger.verifyEquals(true, getpromotersCall.getJsonObject().get("success").getAsBoolean(), "验证返回是否正确");
			JsonArray asJsonArray = getpromotersCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("promoters");
			List<promoter> getAllpromoters = ThirdpartysyncCallService.GetAllpromoters();
			getAllpromoters.forEach(a->{
				boolean flag = false;
				for (int i = 0; i < asJsonArray.size(); i++) {
					int id=asJsonArray.get(i).getAsJsonObject().get("id").getAsInt();
					String name=asJsonArray.get(i).getAsJsonObject().get("name").getAsString();
					if(id==a.getId()){flag=true;};
					if(!name.equals(a.getName())){flag=false;};
					if(flag){break;}
				}
				
				Logger.verifyEquals(true,flag,"验证"+a.getName()+"成功");
				flag=false;
			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}